package com.leetcode.dataStruct.tree;

import com.leetcode.dataStruct.TreeNode;

public class MinDepthTree {
    public static void main(String[] args) {

    }

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        if (root.left == null && root.right == null) {
            return 1;
        }
        int m = minDepth(root.left);
        int n = minDepth(root.right);
        if (root.left == null || root.right == null) {
            return m + n + 1;
        }
        return Math.min(m, n) + 1;
    }
}
